package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FunctionHelper;

public class CEILING extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    if (paramArrayOfObject.length == 1)
    {
      localObject1 = paramArrayOfObject[0];
      if (!(localObject1 instanceof Number))
        break label320;
      return FunctionHelper.parsePrimitiveDouble(Math.ceil(((Number)localObject1).doubleValue()));
    }
    Object localObject1 = paramArrayOfObject[0];
    Object localObject2 = paramArrayOfObject[1];
    if ((localObject1 instanceof Number) && (localObject2 instanceof Number))
    {
      double d1 = ((Number)localObject1).doubleValue();
      double d2 = ((Number)localObject2).doubleValue();
      if (d1 * d2 < 0.0D)
        return Primitive.ERROR_VALUE;
      if (d1 >= 0.0D)
      {
        if ((d2 == 0.0D) || (d1 == 0.0D))
          return new Integer(0);
        if (d2 >= d1)
          return FunctionHelper.parsePrimitiveDouble(d2);
        d3 = 1.0D;
        d3 = Math.round(d1 / d2) - 1L;
        l = ()d3;
        while (l < d3 + 100.0D)
        {
          if (d2 * l >= d1)
          {
            d3 = d2 * l;
            break;
          }
          l += 1L;
        }
        return FunctionHelper.parsePrimitiveDouble(d3);
      }
      if ((d2 == 0.0D) || (d1 == 0.0D))
        return new Integer(0);
      if (d2 <= d1)
        return FunctionHelper.parsePrimitiveDouble(d2);
      double d3 = 1.0D;
      d3 = Math.round(d1 / d2) - 1L;
      long l = ()d3;
      while (l < d3 + 100.0D)
      {
        if (d2 * l <= d1)
        {
          d3 = d2 * l;
          break;
        }
        l += 1L;
      }
      return FunctionHelper.parsePrimitiveDouble(d3);
    }
    label320: return Primitive.ERROR_NAME;
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "CEILING(number,significance): 将参数number沿绝对值增大的方向，舍入为最接近的整数或基数的最小倍数。\nNumber:指待舍入的数值。\nSignificance:基数。\n备注:\n    当number，significance任意一个为非数值型时，CEILING返回错误信息*NAME?。\n    当number，significance符号不同时，CEILING返回错误信息*VALUE?。\n    无论数字符号如何，都按远离零的方向舍入。如果数字已经为significance的倍数，则不进行舍入。\n示例:\nCEILING(2.5,-1)等于*VALUE?。\nCEILING(-2.5,-1)等于-3。\nCEILING(0.5,2)等于2。";
  }

  public String getEN()
  {
    return "CEILING(number,significance): Returns number rounded up, away from zero, to the nearest multiple of significance.\nNumber is the value you want to round.\nSignificance is the multiple to which you want to round.\n\nRemarks:\n1. If either argument is nonnumeric, CEILING returns the #VALUE! error value. \n2. If number and significance have different signs, CEILING returns the #VALUE? error value. \n3. Regardless of the sign of number, a value is rounded up when adjusted away from zero. If number is an exact multiple of significance, no rounding occurs. \n\nExample:\n   CEILING(2.5,-1)=*VALUE?\n   CEILING(-2.5,-1)=-3\n   CEILING(0.5,2)=2";
  }
}